package edu.whu.MagicNote.task;

import edu.whu.MagicNote.dao.LogDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Component
@Slf4j
public class LogCleanTask {
    @Autowired
    private LogDao logDao;

    @Scheduled(cron = "0 0 0 1/10 * ? ") // 每10天触发一次
    public void processTimeOutOrder() {
        LocalDate today = LocalDate.now();
        LocalDateTime time = LocalDateTime.of(today, LocalTime.MIN);
        logDao.DeleteLogBefore(time);
        log.info("开始清理日志: {}", today);
    }
}
